#ifndef xpack_test_math_div
#define xpack_test_math_div
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::test_math_div::inc
#include"test/helper.hpp" // 需要放第一
#include"math/div.hpp"
#include"math/literal.hpp"
#include"math/random.hpp"
#include<math.h>
#pragma pop_macro("xuser")

namespace mixc::test_math_div{
    xtest("div"){
        #define xgen_div()                                      \
            auto mod        = ::fmod(i, j);                     \
            auto expect     = ::round((i - mod) / j);           \
            auto result     = inc::div(i, j);                   \
            auto actually   = result.quotient;                  \
            xassert_fe(expect, actually, i, j)

        #define xgen_mod()                                      \
            expect          = mod;                              \
            actually        = result.remainder;                 \
            xassert_fe(expect, actually, i, j)

        for(f64 i = -64; i < 64; i += 0.123456789){
            for(f64 j = -64; j < 64; j += 0.987654321){
                xgen_div();
                xgen_mod();
            }

            for(f64 j = -64; j < 64; j += 1){
                if (j != 0){
                    xgen_div();
                    xgen_mod();
                }
            }
        }

        for(f64 i = 1.23456789e-310; i < 1.23456789e+300; i *= 10){
            for(f64 j = 2.23456789e-310; j < 2.23456789e+300; j *= 10){
                xgen_div();
                xgen_mod();
            }
        }

        for(f64 i = 1.23456789; i < 1e307; i *= 10){
            for(f64 j = -64; j < 64; j += 0.987654321){
                xgen_div();
                xgen_mod();
            }

            for(f64 j = -64; j < 64; j += 1){
                if (j == 0){
                    continue;
                }
                xgen_div();
                xgen_mod();
            }
        }

        for(f64 i = -1e18; i < 1e18; i += 9.8765432187654321e16){
            for(f64 j = -64; j < 64; j += 0.123456789){
                xgen_div();
                xgen_mod();
            }
        }

        for(f64 i = -1e18; i < 1e18; i += 9.8765432187654321e16){
            for(f64 j = -1024; j < 1024; j += 1){
                if (j == 0){
                    continue;
                }
                xgen_div();
                xgen_mod();
            }
        }

        for(uxx t = 0; t < 16 * 1024; t++){
            f64 i = inc::random<f64>();
            f64 j = inc::random<f64>();
            xgen_div();
            xgen_mod();
        }
    };

    #undef xgen_div
    #undef xgen_mod
}

#endif
